/** \file ATR_t.cc 
 * Test definitions for Average True Range
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: ATR_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "ATR.hpp"
#include <vector>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;


namespace {

const unsigned DataSize = 31;

const double atr_hi[DataSize] = {
  12.3125, 12.2500, 12.3125, 12.2812, 12.3750, 12.3750,
  12.3125, 12.3750, 12.5000, 12.5938, 12.3438, 12.4062,
  12.3750, 12.4062, 12.3750, 12.2812, 12.2500, 12.0625,
  12.3125, 12.3125, 12.3438, 12.6562, 12.6250, 13.0000,
  12.9062, 12.7188, 12.6250, 12.5938, 12.6875, 12.5000,
  12.5000 };

const double atr_lo[DataSize] = {
  12.1875, 12.1562, 12.1875, 12.1250, 12.1250, 12.2812,
  12.1875, 12.1875, 12.2812, 12.3125, 12.2812, 12.2812,
  12.2812, 12.2812, 11.9688, 12.0938, 12.0000, 11.6562,
  12.1562, 12.1250, 12.1562, 12.2812, 12.4688, 12.5625,
  12.6562, 12.6250, 12.4062, 12.4688, 12.4375, 12.4062,
  12.1562 };

const double atr_cls[DataSize] = {
  12.2500, 12.1875, 12.2500, 12.1875, 12.3750, 12.3125,
  12.2188, 12.3438, 12.5000, 12.3750, 12.3438, 12.3438,
  12.2812, 12.3750, 12.0938, 12.1562, 12.0625, 11.9688,
  12.1875, 12.1562, 12.3125, 12.5625, 12.5312, 12.9062,
  12.7500, 12.6250, 12.4375, 12.5625, 12.5000, 12.4062,
  12.1875 };

const double atr_expect[DataSize] = {
  0.1250, 0.1094, 0.1146, 0.1250, 0.1500, 0.1406, 0.1384, 0.1445,
  0.1527, 0.1656, 0.1591, 0.1562, 0.1514, 0.1495, 0.1696, 0.1763, 
  0.1852, 0.2031, 0.2098, 0.2165, 0.2209, 0.2343, 0.2299, 0.2433, 
  0.2544, 0.2544, 0.2633, 0.2656, 0.2544, 0.2477, 0.2544 };


}


TEST(ATRTest, Base)
{
  vector<StockDef> data(DataSize);
  vector<double> result;
  unsigned i;
     
  for(i=0; i<DataSize; ++i) {
    data.at(i).setHi(static_cast<TAfp_t>(atr_hi[i]));
    data.at(i).setLo(static_cast<TAfp_t>(atr_lo[i]));
    data.at(i).setCls(static_cast<TAfp_t>(atr_cls[i]));
  }


  ATR(data.begin(), data.end(),
      back_inserter(result),
      14, SecurityAdaptor<StockDef>());
  TC_TEST(result.size()==DataSize);
  for(i=14; i<DataSize; ++i) {
    TC_TESTFP(atr_expect[i], result[i]);
  }

  PrintElements(result, "ATR values");
}


  
